﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace AgLux
{
    /// <summary>
    /// Represents a component that displays an audio clip.
    /// </summary>

    public class Audio : Media
    {
        /// <summary>
        /// Initializes a new instance of the Audio class.
        /// </summary>

        /// <param name="source">
        /// The audio source.
        /// </param>

        /// <param name="caption">
        /// The audio caption.
        /// </param>

        /// <param name="transcript">
        /// The audio transcript source.
        /// </param>

        public Audio(string source, string caption, string transcript)
            : base(source, caption, transcript, 1)
        {
            _mediaPanel.RenderTransformOrigin = new Point(0, 0);

            GradientStop _enterMediaFullScreenColor1 = (GradientStop)_resource.FindName("enterMediaFullScreenColor1");
            GradientStop _enterMediaFullScreenColor2 = (GradientStop)_resource.FindName("enterMediaFullScreenColor2");
            GradientStop _enterMediaFullScreenColor3 = (GradientStop)_resource.FindName("enterMediaFullScreenColor3");
            _enterMediaFullScreenColor1.Color = _enterMediaFullScreenColor2.Color = _enterMediaFullScreenColor3.Color = Colors.Black;
        }

        /// <summary>
        /// Prepare to display the media.
        /// </summary>

        /// <param name="width">
        /// The width of the canvas on which the media will be displayed.
        /// </param>

        public override void Prepare(double width)
        {
            base.Prepare(width);
            _mediaPanelScale.ScaleX = _mediaPanelScale.ScaleY = width / _mediaPanel.Width / 2;
            _screen.Width = _panelArea.Width = _mediaPanel.Width * _mediaPanelScale.ScaleX;

            _screen.Height = _panelArea.Width = _mediaPanel.Height * _mediaPanelScale.ScaleX;
            SetCaption(_screen.Width);
            Height = _screen.Height + _caption.Height + 5;
            _caption.SetValue(Canvas.TopProperty, Height - _caption.Height);
        }
    }
}
